package com.egao.common.module.recommendation.controller;

import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.recommendation.entity.RecommendationUndergraduateEmployment;
import com.egao.common.module.recommendation.entity.vo.RecommendationAuditParam;
import com.egao.common.module.recommendation.entity.vo.RecommendationListVo;
import com.egao.common.module.recommendation.service.IRecommendationUndergraduateEmploymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  控制器
 *
 * @author ly
 */
@Api(tags = "管理")
@RestController
@RequestMapping("${api}")
public class RecommendationUndergraduateEmploymentController extends BaseController {

    private IRecommendationUndergraduateEmploymentService recommendationUndergraduateEmploymentService;

    @Autowired
    public RecommendationUndergraduateEmploymentController(IRecommendationUndergraduateEmploymentService recommendationUndergraduateEmploymentService){
        this.recommendationUndergraduateEmploymentService = recommendationUndergraduateEmploymentService;
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:list')")
    @ApiOperation("查询列表")
    @GetMapping("/recUnderEmpl/list")
    public PageResult<RecommendationListVo> list(HttpServletRequest request) {
        PageParam<RecommendationUndergraduateEmployment> pageParam = new PageParam<>(request);
        return recommendationUndergraduateEmploymentService.list(pageParam);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:read')")
    @ApiOperation("查询单个")
    @GetMapping("/recUnderEmpl/read/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return recommendationUndergraduateEmploymentService.read(id);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:my')")
    @ApiOperation("查询单个")
    @GetMapping("/recUnderEmpl/my")
    public JsonResult read() {
        return recommendationUndergraduateEmploymentService.read();
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:add')")
    @ApiOperation("提交推荐表 id为空")
    @PostMapping("/recUnderEmpl/add")
    public JsonResult add(@RequestBody RecommendationUndergraduateEmployment model) {
        return recommendationUndergraduateEmploymentService.add(model);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:submit')")
    @ApiOperation("提交推荐表 id不为空")
    @PostMapping("/recUnderEmpl/submit/{id}")
    public JsonResult submit(@PathVariable("id") Integer id) {
        return recommendationUndergraduateEmploymentService.submit(id);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:update')")
    @ApiOperation("保存")
    @PostMapping("/recUnderEmpl/update")
    public JsonResult update(@RequestBody RecommendationUndergraduateEmployment model) {
        return recommendationUndergraduateEmploymentService.update(model);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:audit')")
    @ApiOperation("辅导员审核")
    @PostMapping("/recUnderEmpl/audit")
    public JsonResult audit(@RequestBody RecommendationAuditParam param) {
        return recommendationUndergraduateEmploymentService.audit(param);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:delete')")
    @ApiOperation("删除就业推荐表记录")
    @PutMapping("/recUnderEmpl/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return recommendationUndergraduateEmploymentService.delete(ids);
    }

    @PreAuthorize("hasAuthority('recUnderEmpl:export')")
    @ApiOperation("导出")
    @GetMapping("/recUnderEmpl/export/{id}")
    public JsonResult export(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException {
        return recommendationUndergraduateEmploymentService.export(id,response);
    }

}